package com.cyj.dream.core.base;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @Description: 基础类
 * @BelongsProject: DreamChardonnay
 * @BelongsPackage: com.cyj.dream.core.base
 * @Author: ChenYongJia
 * @CreateTime: 2021-10-20 16:10
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Data
@MappedSuperclass
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @TableId(value = "dream_id", type = IdType.ASSIGN_ID)
    @ExcelIgnore
    @Column( nullable = false , columnDefinition = "VARCHAR(255) COMMENT '逻辑id主键'")
    private String dreamId;

    /**
     * 创建人
     */
    @TableField(fill = FieldFill.INSERT)
    @Column( columnDefinition = "VARCHAR(255) COMMENT '创建人'")
    private String creator;

    /**
     * 创建人id
     */
    @TableField(fill = FieldFill.INSERT)
    @Column(name="creator_id", columnDefinition = "VARCHAR(255) COMMENT '创建人id'")
    private String creatorId;

    /**
     * 创建人部门id
     */
    @TableField(fill = FieldFill.INSERT)
    @Column(name="creator_dept_id", columnDefinition = "bigint(20) COMMENT '创建人部门ID'")
    private String creatorDeptId;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    @Column(name="create_time", nullable = false , columnDefinition = "DATETIME COMMENT '创建时间'")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Column(name="update_time", nullable = false , columnDefinition = "DATETIME COMMENT '修改时间'")
    private LocalDateTime updateTime;

    /**
     * 乐观锁字段
     */
    @Version
    @Column(nullable = false , columnDefinition = "INT  COMMENT '版本' default 1")
    private Integer version;

    /**
     * 删除标识符
     */
    @TableLogic
    @TableField(select = false)
    @Column(nullable = false , columnDefinition = "INT  COMMENT '逻辑删除标识(0.未删除,1.已删除)' default 0")
    private Integer delFlag;

}

